<%@ taglib prefix="s" uri="/struts-tags" %>
<%--
  Created by IntelliJ IDEA.
  User: liuziyang
  Date: 2018/10/7
  Time: 21:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Employees</title>
    <script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(function () {
            //1.点击delete时，弹出是否确定是要删除xx的信息么？若确定，执行删除，若不确定，不执行。
            $(".delete").click(function () {
                var lastName = $(this).next(":hidden").val();
                var flag = confirm("确定要删除" + lastName + "的信息么？");
                if (flag) {
                    var $tr = $(this).parent().parent();
                    //删除，使用ajax的方式
                    var url = this.href;
                    var args = {"time": new Date()};
                    $.post(url, args, function (data) {
                        //若data的返回为1,则提示删除成功，且把当前行删除
                        if (data === "1") {
                            alert("删除成功");
                            $tr.remove();
                        } else {
                            //若data的返回值不是1则提示删除失败
                            alert("删除失败");
                        }
                    })
                }
                // 取消超链接默认的行为
                return false;
            })
        })
    </script>
</head>
<body>
<h4>Employee List Page</h4>
<s:if test="#request.employees == null || #request.employees.size==0">
    没有任何员工信息
</s:if>
<s:else>
    <table border="1" cellpadding="10" cellspacing="0">
        <tr>
            <td>ID</td>
            <td>LASTNAME</td>
            <td>EMAIL</td>
            <td>BIRTH</td>
            <td>CREATETIME</td>
            <td>DEPT</td>
            <td>DELETE</td>
            <td>EDIT</td>
        </tr>
        <s:iterator value="#request.employees">
            <tr>
                <td>${id}</td>
                <td>${lastName}</td>
                <td>${email}</td>
                <td>
                    <s:date name="birth" format="yyyy-MM-dd"/>
                </td>
                <td>
                    <s:date name="createTime" format="yyyy-MM-dd HH:mm:ss"/>
                </td>
                <td>${department.departmentName}</td>
                <td>
                    <a class="delete" href="emp-delete.action?id=${id}">Delete</a>
                    <input type="hidden" value="${lastName}"/>
                </td>
                <td>
                    <a href="emp-input.action?id=${id}">Edit</a>
                </td>
            </tr>
        </s:iterator>
    </table>
</s:else>
<br/>
<a href="returnmain.action">Return to main page</a>
</body>
</html>
